package com.ruoyi.web.controller.productionre;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.production.domain.BladeReturn;
import com.ruoyi.production.domain.SimpleProduction;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.GreenhousefilmReturn;
import com.ruoyi.production.service.IGreenhousefilmReturnService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 棚膜退回Controller
 *
 * @author ruoyi
 * @date 2021-07-21
 */
@Api("棚膜退回")
@RestController
@RequestMapping("/production/greenhousefilmre")
public class GreenhousefilmReturnController extends BaseController
{
    @Autowired
    private IGreenhousefilmReturnService greenhousefilmReturnService;

    /**
     * 查询棚膜退回列表
     */
    @ApiOperation("查询棚膜退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:list')")
    @GetMapping("/list")
    public TableDataInfo list(GreenhousefilmReturn greenhousefilmReturn)
    {
        startPage();
        List<GreenhousefilmReturn> list = greenhousefilmReturnService.selectGreenhousefilmReturnList(greenhousefilmReturn);
        return getDataTable(list);
    }

    /**
     * 导出棚膜退回列表
     */
    @ApiOperation("导出棚膜退回列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:export')")
    @Log(title = "棚膜退回", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GreenhousefilmReturn greenhousefilmReturn)
    {
        List<GreenhousefilmReturn> list=new ArrayList();
        //通过id来取
        Long a[]=greenhousefilmReturn.getGreenhousefilmReturnIds();
        for(int i=0;i<a.length;i++) {
            GreenhousefilmReturn list1 = greenhousefilmReturnService.selectGreenhousefilmReturnById(a[i]);
            list.add(list1);
        }

        ExcelUtil<GreenhousefilmReturn> util = new ExcelUtil<GreenhousefilmReturn>(GreenhousefilmReturn.class);
        return util.exportExcel(list, "棚膜退回数据");
    }

    /**
     * 获取棚膜退回详细信息
     */
    @ApiOperation("获取棚膜退回详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:query')")
    @GetMapping(value = "/{greenhousefilmReturnId}")
    public AjaxResult getInfo(@PathVariable("greenhousefilmReturnId") Long greenhousefilmReturnId)
    {
        return AjaxResult.success(greenhousefilmReturnService.selectGreenhousefilmReturnById(greenhousefilmReturnId));
    }

    /**
     * 新增棚膜退回
     */
    @ApiOperation("新增棚膜退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:add')")
    @Log(title = "棚膜退回", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GreenhousefilmReturn greenhousefilmReturn)
    {
        return toAjax(greenhousefilmReturnService.insertGreenhousefilmReturn(greenhousefilmReturn));
    }

    /**
     * 修改棚膜退回
     */
    @ApiOperation("修改棚膜退回")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('production:greenhousefilmre:edit,production:greenhousefilmre:permit')")
    @Log(title = "棚膜退回", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GreenhousefilmReturn greenhousefilmReturn)
    {
        return toAjax(greenhousefilmReturnService.updateGreenhousefilmReturn(greenhousefilmReturn));
    }

    /**
     * 删除棚膜退回
     */
    @ApiOperation("删除棚膜退回")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:remove')")
    @Log(title = "棚膜退回", businessType = BusinessType.DELETE)
	@DeleteMapping("/{greenhousefilmReturnIds}")
    public AjaxResult remove(@PathVariable Long[] greenhousefilmReturnIds)
    {
        return toAjax(greenhousefilmReturnService.deleteGreenhousefilmReturnByIds(greenhousefilmReturnIds));
    }

    /**
     * 获取棚膜类型下拉框
     */
    @ApiOperation("获取棚膜类型下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:type')")
    @GetMapping("/type")
    public TableDataInfo getType(){

        List<GreenhousefilmReturn> list = greenhousefilmReturnService.getGreenhousefilmType();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (GreenhousefilmReturn greenhousefilmReturn:list) {
            Long id = greenhousefilmReturn.getGreenhousefilmTypeId();
            String name = greenhousefilmReturn.getGreenhousefilmType();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取用户列表下拉框
     */
    @ApiOperation("获取用户列表下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:username')")
    @GetMapping("/username")
    public TableDataInfo getUserName(){

        List<GreenhousefilmReturn> list = greenhousefilmReturnService.getUserName();
        List<SimpleProduction> simpleProductions = new ArrayList<>();
        for (GreenhousefilmReturn greenhousefilmReturn:list) {
            Long id = greenhousefilmReturn.getUserId();
            String name = greenhousefilmReturn.getUserName();
            SimpleProduction simpleProduction = new SimpleProduction(id,name);
            simpleProductions.add(simpleProduction);
        }
        return getDataTable(simpleProductions);
    }

    /**
     * 获取棚膜厚度下拉框
     */
    @ApiOperation("获取棚膜厚度下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:thickness')")
    @GetMapping("/thickness/{greenhousefilmTypeId}")
    public TableDataInfo getThickness(@PathVariable("greenhousefilmTypeId") Long greenhousefilmTypeId){

        List<Double> list = greenhousefilmReturnService.getThickness(greenhousefilmTypeId);
        return getDataTable(list);
    }

    /**
     * 获取公司下拉框
     */
    @ApiOperation("获取公司下拉框")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('production:greenhousefilmre:origincompany')")
    @GetMapping("/origincompany/{greenhousefilmTypeId}")
    public TableDataInfo getOriginCompany(@PathVariable("greenhousefilmTypeId") Long greenhousefilmTypeId){

        List<String> list = greenhousefilmReturnService.getOriginCompany(greenhousefilmTypeId);
        return getDataTable(list);
    }
}
